<?php

if( ! defined('DOCROOT') )
{
    require_once '/var/www/advancelab/chilik2/unittest/bootstrap.php';
}

class JsonViewTest extends UnitTestCase
{
    function testinginstanceof()
    {
        $view = new Entity\JsonView( 'test1' );
        $this->assertTrue( $view instanceof Base\ViewHandler );
    }
    
    function testingSimpleView()
    {
        $view = new Entity\JsonView( 'test1' );
        $view->assign( 'name', 'Churchill' );
        $view->assign( 'quote', '”Genius is independent of situation.”' );
        /* $view->render(); */
        
        $this->assertEqual( '{"name":"Churchill","quote":"\u201dGenius is independent of situation.\u201d"}', $view->getResult() );
    }
    
    function testingNonLastSimpleView()
    {
        $view = new Entity\JsonView( 'test2' );
        $view->assign( 'name', 'Churchill' );
        $view->assign( 'quote', '”Genius is independent of situation.”' );
        /* $view->render(); */
        
        $this->assertEqual( array('name' => "Churchill", "quote" => '”Genius is independent of situation.”'), $view->getResult( FALSE ) );
    }
    
    function testingOneView(  )
    {
        $request = new Core\MVCRequest();
        $result = new Entity\MVCResult();
        
        $result->variables = array('name' => "Churchill", "quote" => '”Genius is independent of situation.”');
        
        $view = new TestOneJsonView( $request, $result );
        $response = $view->createResponse();
        
        $this->assertEqual(json_encode($result->variables), $response->body);
    }
    
    function testingTwoView()
    {
        $request = new Core\MVCRequest();
        $result = new Entity\MVCResult();
        
        $result->variables = array('name' => "Churchill", "quote" => '”Genius is independent of situation.”',
            'navMaxPages' => 5, 'navCurrentPage' => 2);
        
        $view = new TestTwoJsonView( $request, $result );
        $response = $view->createResponse();
        
        $this->assertEqual('{"name":"Churchill","quote":"u201dGenius is independent of situation.u201d","navMaxPages":5,"navCurrentPage":2,"nav":"{"name":"Churchill","quote":"\u201dGenius is independent of situation.\u201d","navMaxPages":5,"navCurrentPage":2}"}', stripslashes($response->body));
    }
}

